<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

namespace support;

use Illuminate\Support\Traits\Macroable;
use model\AdminUserModel;
use Tinywan\Jwt\JwtToken;

/**
 * Class Request
 * @package support
 * @method int adminId() macro 获取当前登录管理员管理员id
 * @method AdminUserModel adminUser() macro 获取当前管理员
 * @method JwtToken jwt() macro 获取jwt
 */
class Request extends \Webman\Http\Request
{
    use Macroable;

    /**
     * 重写框架request->all() 修复获取不到路由中pathvariable
     * @return array|mixed|null
     */
    public function all() {
        $data = $this->post() + $this->get();
        if (!empty($this->route->param())) {
            $data = $data + $this->route->param();
        }
        return $data;
    }

    /**
     * 重写框架request->input() 修复获取不到路由中pathvariable
     * @param string $name
     * @param $default
     * @return array|mixed|null
     */
    public function input(string $name, $default = null) {
        $post = $this->post();
        if (isset($post[$name])) {
            return $post[$name];
        }
        $get = $this->get();
        if (isset($get[$name])) {
            return $get[$name];
        }
        return $this->route->param($name, $default);
    }
}
